﻿<%@ WebHandler Language="C#" Class="ContractQuickSearch" %>

using System;
using System.Web;
using System.Text;
using System.Collections.Generic;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business.BLL;

public class ContractQuickSearch : AjaxHandlerBase
{

    //*******************************************
    //功能概要       ：基本权限初始化设定
    //参数説明       ：-
    //返回值説明     ：-
    //功能詳細       ：权限哈希表中添加操作与权限组
    //作成者         ：he.jifeng 
    //作成日         ：2010-07-14
    //*******************************************
    public ContractQuickSearch()
    {
        //成交记录--导出
        htTypePermit.Add("export", Constants.Permit_Bargain_Export);  
    }
    
    //*******************************************
    //功能概要       ：请求处理
    //参数説明       ：context 请求上下文
    //返回值説明     ：-
    //功能詳細       ：根据请求名 分发请求
    //作成者         ：he.jifeng
    //作成日         ：2010-09-25
    //*******************************************
    override public void RequestProcess(HttpContext context)
    {
        try
        {
            context.Response.ContentType = "text/plain";
            context.Response.AddHeader("pragma", "no-cache");
            context.Response.AddHeader("cache-control", "");
            context.Response.CacheControl = "no-cache";

            string strOp = context.Request["op"];
            string strRet = string.Empty;
            switch (strOp.ToLower())
            {
                //查询
                case "search":
                    strRet = QuickSearchContract(context);
                    break;
                default:
                    break;
            }
            context.Response.Write(strRet);
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }

    //*******************************************
    //功能概要       ：快速查询合同
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：快速查询合同
    //作成者         ：he.jifeng
    //作成日         ：2010-09-25
    //*******************************************
    private string QuickSearchContract(HttpContext context)
    {
        string strRet = string.Empty;
        string strParam = string.Empty;
        StringBuilder strHtml = new StringBuilder();

        Dictionary<string, string> dicParams = new Dictionary<string, string>();
        ContractBaseInfo bllBaseInfo = new ContractBaseInfo();

        strParam = context.Request.Params["pagesize"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageSize", strParam);
        }
        strParam = context.Request.Params["pageindex"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("PageIndex", strParam);
        }
        strParam = context.Request.Params["sort"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("Sort", strParam);
        }
        strParam = context.Request.Params["StartTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("StartTime", strParam);
        }
        strParam = context.Request.Params["EndTime"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("EndTime", strParam);
        }
        strParam = context.Request.Params["Keyword"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("Keyword", strParam);
        }
        strParam = context.Request.Params["BusinessType"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("BusinessType", strParam);
        }
        
        strParam = context.Request.Params["AreaS"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("AreaS", strParam);
        }
        strParam = context.Request.Params["AreaE"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("AreaE", strParam);
        }
        strParam = context.Request.Params["BargainPriceS"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("BargainPriceS", strParam);
        }
        strParam = context.Request.Params["BargainPriceE"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("BargainPriceE", strParam);
        }
        strParam = context.Request.Params["ArchivementDate"];
        if (!string.IsNullOrEmpty(strParam))
        {
            dicParams.Add("ArchivementDate", strParam);
        }
        
        if (!string.IsNullOrEmpty(context.Request.Params["departid"]))
        {
            dicParams.Add("DepartId", context.Request.Params["departid"]);
        }
        else if (!string.IsNullOrEmpty(context.Request.Params["areaid"]))
        {
            dicParams.Add("AreaId", context.Request.Params["areaid"]);
        }
        else if (!string.IsNullOrEmpty(context.Request.Params["companyid"]))
        {
            dicParams.Add("CompanyId", context.Request.Params["companyid"]);
        }
        if (!string.IsNullOrEmpty(context.Request.Params["cityid"]))
        {
            dicParams.Add("CityId", context.Request.Params["cityid"]);
        }
        else
        {
            dicParams.Add("CompanyId", CurrentUserInfo.CompanyId.ToString());
        }

        /*
        //查看所有
        if (CurrentUserInfo.ContainsPermit(Constants.Pertmi_ViewAllContractsQuick))
        {
        }
        //查看本城市
        else if (CurrentUserInfo.ContainsPermit(Constants.Pertmi_ViewCityContractsQuick))
        {
            if (!dicParams.ContainsKey("CityId"))
            {
                dicParams.Add("CityId", CurrentUserInfo.CityId.ToString());
            }
        }
        //查看本公司
        else if (CurrentUserInfo.ContainsPermit(Constants.Pertmi_ViewCompanyContractsQuick))
        {
            if (!dicParams.ContainsKey("CompanyId"))
            {
                dicParams.Add("CompanyId", CurrentUserInfo.CompanyId.ToString());
            }
        }
        else
        {
            dicParams.Add("CurUserId", CurrentUserInfo.UserId.ToString());
        }
        */
        System.Data.DataSet dsBaseInfo = bllBaseInfo.GetListByParams(dicParams);

        strHtml.Append("{");
        strHtml.Append("success:'1',");
        strHtml.Append("msg:'',");
        strHtml.AppendFormat("data:{{{0},", JsonHelp.Convert2Json(dsBaseInfo.Tables[0]));
        strHtml.AppendFormat("count:'{0}'", dsBaseInfo.Tables[1].Rows[0][0]);
        strHtml.Append("}");
        strHtml.Append("}");

        strRet = strHtml.ToString();

        return strRet;
    }
}